'''
description:我的实验模块编辑接口测试
author:陈杨涛
'''
import json
import unittest
import requests
from jsonpath import jsonpath
from parameterized import parameterized

from utils.reader import Reader
from utils.session import Session


class AniamlEdit(unittest.TestCase):
    """
    author:陈杨涛
    description:我的实验编辑类
    """
    s = None
    session_token = None
    @classmethod
    def setUpClass(cls) -> None:
        cls.s = Session.get_session()
        cls.session_token = Session.get_header()
    @classmethod
    def tearDownClass(cls) -> None:
        cls.s.close()

    #传入用例数据
    @parameterized.expand(Reader.read_excel('animal.xlsx', min_row=23, max_row=30, min_col=7, max_col=10))
    def test_order(self, commit, url, param, expected):
        """
        编辑 =》动物订购
        """
        data = json.loads(param)
        if commit == 'POST':
            resp = self.s.post(url, json=data, headers=self.session_token)
            # 将相应正文转换成字典类型
            # print(resp.text,type(resp.text))
            text_result = json.loads(resp.text)


            if expected == 404:
                self.assertEqual(404, resp.status_code)
                # 获取响应结果的status
                text_result1 = text_result['status']

                self.assertEqual(expected, text_result1)

            else:
                self.assertEqual(200, resp.status_code)
                # 获取相应结果的resCode
                text_result2 = text_result['resCode']
                self.assertEqual(expected, text_result2)
        if commit == 'GET':
            resp = self.s.get(url, json=data, headers=self.session_token)
            self.assertEqual(200, resp.status_code)
            self.assertEqual(0, resp.text['resCode'])